﻿#Include ..\baseHandle.ahk

#Include ..\..\_lib\WtRunner.ahk
#Include ..\..\_lib\Path.ahk

class Wt extends BaseHandle {

  static Handle(parsed) {
    ts := [parsed.target, parsed.extra*]
    cfs := MeowConf.Of('./cfg/wtFile.txt')
    i := WtRunner.Builder()
    ts.forEach(v => _process(v))
    _process(t) {
      if not r := cfs.Get(t)
        throw Error('无效的执行目标:' t)
      i.NewTab(
        r.tabName,
        r['profile'] || unset,
        r['tabColor'] || unset,
        parsed.getKV('execPath', r.execPath),
        r['command'] || unset
      )
        .Window(r.window)
    }
    i.Build().RunCmd()
    return this.Succ('ok', 'x')
  }
  static Spec() {
    return {
      cmd: 'wt',
      desc: '使用终端打开配置文件中的exe',
      format: 'wt <target>',
      args: {
        desc: '',
        isOptional: false,
        cacheable: true,
        generator: {
          script: '',
          postProcess: (*) => MeowConf.Of('./cfg/wtFile.txt').data.keys.filter(v => v[1] != '!')
        }
      },
      extra: {
        isEnable: false
      }
    }
  }
}

; # for [wt] command
; # 必要参数 window tabName execPath
; # 可选参数 profile tabColor command

; !profiles: 
; + Git   : 'Git Bash'
; + Psl7  : 'PowerShell7'
; + Cmd   : 'Command Prompt'

; redis :    # run redis server
; + window   : 0
; + tabName  : redis-server
; + tabColor : #97d1f3
; + execPath : E:\_Program\Redis-x64-5.0.14.1
; + command  : '.\redis-server.exe redis.windows.conf'